package com.shujia.wyh.day10;

import java.util.ArrayList;

/*
    去除集合中自定义对象的重复值(对象的成员变量值都相同)
 */
public class ArrayListTest2 {
    public static void main(String[] args) {
        //创建集合对象
        ArrayList list1 = new ArrayList();

        //2、创建元素对象
        Student s1 = new Student("吴涛", 18);
        Student s2 = new Student("陈涛", 16);
        Student s3 = new Student("王辉煌", 17);
        Student s4 = new Student("张梦云", 19);
        Student s5 = new Student("吴涛", 18);

        //3、将元素添加到集合中
        list1.add(s1);
        list1.add(s2);
        list1.add(s3);
        list1.add(s4);
        list1.add(s5);

        System.out.println(list1);

        //4、创建新的集合
        ArrayList list2 = new ArrayList();

        //5、遍历旧的集合
        for (int i = 0; i < list1.size(); i++) {
            Student s = (Student) list1.get(i);
            if(!list2.contains(s)){
                list2.add(s);
            }
        }

        System.out.println(list2);
    }
}
